package com.hdumooc.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @description: DML 操作示例
 * @author: Jieyao Lu
 * @date: 2023/11/18 15:44
**/
public class JDBCDemo01 {
    public static void main(String[] args) throws Exception {
        // 1.注册驱动(可以省略)
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.获取连接(url, username, password)
        String url = "jdbc:mysql://localhost:3306/jdbc_lessons?characterEncoding=UTF-8";
        Connection connection = DriverManager.getConnection(url, "root", "root");
        // 3.获取SQL执行对象 Statement
        Statement statement = connection.createStatement();
        // 4.执行DML操作 executeUpdate
        String sql = "create table test01(id int, name varchar(20),age int);";
        int i = statement.executeUpdate(sql); // 返回值是受影响的行数
        System.out.println(i);
        // 5.关闭流
        statement.close();
        connection.close();
    }
}
